import { GSprite } from "../../../../../com/mui/controls/GSprite";
import { Cache } from "../../../cache/Cache";
import { ENpcEffect } from "../../../../../Message/Public/ENpcEffect";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
import { FlyFootBmp } from "../../mapUI/flyFoot/FlyFootBmp";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MsgManager } from "../../../manager/MsgManager";
import { GameConst } from "../../../../component/gconst/GameConst";
import { EPrictUnit } from "../../../../../Message/Public/EPrictUnit";
import { SArenaCrossBetPlayerInfos } from "../../../../../Message/Public/SArenaCrossBetPlayerInfos";
import { AvatarInfo } from "../../../resource/info/AvatarInfo";
import { AvatarType } from "../../../resource/info/AvatarType";
import { ImageInfo } from "../../../../../com/gengine/resource/info/ImageInfo";
import { EntityUtil } from "../../../scene/layer/utils/EntityUtil";
import { CareerConfig } from "../../../resource/CareerConfig";
import { AIManager } from "../../../scene/ai/AIManager";
import { AIType } from "../../../scene/ai/AIType";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { TaskTargetInfo } from "../../../model/TaskTargetInfo";
import { _finalPosType } from "../../../../../this/_finalPosType";
import { _finalPos } from "../../../../../this/_finalPos";
import { _EPriceUnitGold } from "../../../../../EPrictUnit/_EPriceUnitGold";
type int = number;
//class ArenaCrossBetGoldPanel
    
    export  class ArenaCrossBetGoldPanel extends GSprite
    {
        constructor()
        {
            super();
            this.glowFilterY = new Object /* flash.filters.GlowFilter */(268435302, 1, 6, 6, 4);
            this.filterArr = [this.glowFilterY];
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this._targetInfo = Cache.instance.scene.getNpcByEffect(ENpcEffect._ENpcEffectArenaCrossShop);
            this._sp = new Object /* flash.display.Sprite */();
            addChild(this._sp);
            var loc1=ObjCreate.createGTextField(Language.getString(44384), 0, 2, 464, 20, this, GlobalStyle.textFormat6);
            loc1.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._oneName = ObjCreate.createTextField("", 68, 20, 96, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 11661311, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._twoName = ObjCreate.createTextField("", 301, 20, 96, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 11661311, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            var loc2=new Object /* flash.display.Bitmap */();
            loc2.x = 66;
            loc2.y = 24;
            this._sp.addChild(loc2);
            LoaderHelp.setBitmapdata("Friend_Bg_Head.swf", loc2);
            var loc3=new Object /* flash.display.Bitmap */();
            loc3.x = 300;
            loc3.y = 24;
            this._sp.addChild(loc3);
            LoaderHelp.setBitmapdata("Friend_Bg_Head.swf", loc3);
            this._oneHeadImage = new Object /* flash.display.Bitmap */();
            this._twoHeadImage = new Object /* flash.display.Bitmap */();
            this._oneHeadImage.x = 85;
            this._oneHeadImage.y = 42;
            this._twoHeadImage.x = 318;
            this._twoHeadImage.y = 42;
            this._sp.addChild(this._oneHeadImage);
            this._sp.addChild(this._twoHeadImage);
            var loc4=ObjCreate.createTextField(Language.getString(44304), 56, 120, 52, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            var loc5=ObjCreate.createTextField(Language.getString(44304), 286, 120, 52, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._oneServerTx = ObjCreate.createTextField("", 106, 120, 72, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 65535));
            this._twoServerTx = ObjCreate.createTextField("", 336, 120, 72, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 65535));
            this._oneInfoTx = ObjCreate.createTextField("", 56, 142, 100, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._twoInfoTx = ObjCreate.createTextField("", 286, 142, 100, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            var loc6=ObjCreate.createTextField(Language.getString(44305), 56, 164, 52, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            var loc7=ObjCreate.createTextField(Language.getString(44305), 286, 164, 52, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            this._oneWarfareTx = ObjCreate.createTextField("", 106, 164, 72, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 16744512));
            this._twoWarfareTx = ObjCreate.createTextField("", 336, 164, 72, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 16744512));
            loc1 = ObjCreate.createTextField("", 56, 186, 165, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            loc1.htmlText = Language.getString(44381);
            loc1 = ObjCreate.createTextField("", 286, 186, 165, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            loc1.htmlText = Language.getString(44381);
            loc1 = ObjCreate.createTextField("", 56, 208, 165, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            loc1.htmlText = Language.getString(44382);
            loc1 = ObjCreate.createTextField("", 286, 208, 165, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            loc1.htmlText = Language.getString(44382);
            var loc8=ObjCreate.createTextField(Language.getString(44309), 36, 252, 75, 24, this._sp, new GTextFormat(FontUtil.songtiName, 14, 11661311, true));
            var loc9=ObjCreate.createTextField(Language.getString(44309), 266, 252, 75, 24, this._sp, new GTextFormat(FontUtil.songtiName, 14, 11661311, true));
            this._oneMyBetTx = ObjCreate.createTextField("", 110, 252, 80, 20, this._sp, new GTextFormat(FontUtil.songtiName, 14, 16744512));
            this._twoMyBetTx = ObjCreate.createTextField("", 344, 252, 80, 20, this._sp, new GTextFormat(FontUtil.songtiName, 14, 16744512));
            ObjCreate.createBitmap(ImagesConst.Yuanbao_small, 181, 257, this._sp);
            ObjCreate.createBitmap(ImagesConst.Yuanbao_small, 413, 257, this._sp);
            var loc10;
            (loc10 = GlobalStyle.textFormat1).align = flash.text.TextFormatAlign.RIGHT;
            this._oneBetNumInputTx = new GTextInput();
            this._oneBetNumInputTx.styleName = "GTextInput";
            this._oneBetNumInputTx.textField.selectable = true;
            this._oneBetNumInputTx.restrict = "0-9";
            this._oneBetNumInputTx.maxChars = 4;
            this._oneBetNumInputTx.setSize(97, 25);
            this._oneBetNumInputTx.move(62, 277);
            this._sp.addChild(this._oneBetNumInputTx);
            this._twoBetNumInputTx = new GTextInput();
            this._twoBetNumInputTx.styleName = "GTextInput";
            this._twoBetNumInputTx.textField.selectable = true;
            this._twoBetNumInputTx.restrict = "0-9";
            this._twoBetNumInputTx.maxChars = 4;
            this._twoBetNumInputTx.setSize(97, 25);
            this._twoBetNumInputTx.move(297, 277);
            this._sp.addChild(this._twoBetNumInputTx);
            this._oneBetNumInputTx.addEventListener(flash.events.Event.CHANGE, this.onBetNumInputTxChange);
            this._twoBetNumInputTx.addEventListener(flash.events.Event.CHANGE, this.onBetNumInputTxChange);
            ObjCreate.createBitmap(ImagesConst.Yuanbao_small, 181, 280, this._sp);
            ObjCreate.createBitmap(ImagesConst.Yuanbao_small, 413, 280, this._sp);
            this._oneBetBtn = ObjCreate.createGButton(Language.getString(44303), 74, 308, 72, 26, this._sp, "ArenaRedBtn");
            this._twoBetBtn = ObjCreate.createGButton(Language.getString(44303), 311, 308, 72, 26, this._sp, "ArenaRedBtn");
            this._oneBetBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBetBtnClick);
            this._twoBetBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBetBtnClick);
            var loc11;
            (loc11 = ObjCreate.createTextField("", 10, 352, 450, 20, this._sp, GlobalStyle.textFormat6)).autoSize = flash.text.TextFieldAutoSize.LEFT;
            loc11.multiline = true;
            loc11.wordWrap = true;
            loc11.htmlText = Language.getString(44383);
            loc11.addEventListener(flash.events.TextEvent.LINK, this.onLinkClickHandler);
            this._flyFoot = new FlyFootBmp();
            this._flyFoot.x = 393;
            this._flyFoot.y = 350;
            this._flyFoot.addEventListener(flash.events.MouseEvent.CLICK, this.onFlyFootClickHandler);
            this.addChild(this._flyFoot);
            ObjCreate.createTextField(Language.getString(44385), 300, 378, 65, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 16776960));
            var loc12;
            (loc12 = ResouceConst.getScaleBitmap(ImagesConst.DisabledBg)).x = 365;
            loc12.y = 377;
            loc12.setSize(64, 22);
            this._sp.addChild(loc12);
            ObjCreate.createBitmap(ImagesConst.Wangzhebi, 435, 378, this._sp);
            this._myArenaCrossCoinTxt = ObjCreate.createTextField("0", 366, 378, 60, 20, this._sp, new GTextFormat(FontUtil.songtiName, 12, 11661311, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._myGoldTxt = ObjCreate.createTextField("0", 69, 378, 60, 20, null, new GTextFormat(FontUtil.songtiName, 12, 11661311, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._myGoldTxt.text = Cache.instance.role.money.gold.toString();
            return;
        }

        public setPlayerData(arg1: int, arg2: int): void
        {
            this._finalPosType = arg1;
            this._finalPos = arg2;
            if (this._finalPosType > 0) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCrossGetTwoPlayerBetInfo, {"finalPosType": _finalPosType, "finalPos": _finalPos}));
            }
            return;
        }

        protected onBetNumInputTxChange(arg1: Object /* flash.events.Event */): void
        {
            var loc1=arg1.target;
            switch (loc1) 
            {
                case this._oneBetNumInputTx:
                {
                    this.confirmCoin(this._oneBetNumInputTx);
                    break;
                }
                case this._twoBetNumInputTx:
                {
                    this.confirmCoin(this._twoBetNumInputTx);
                    break;
                }
            }
            return;
        }

        protected onBetBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=0;
            var loc2=arg1.target;
            switch (loc2) 
            {
                case this._oneBetBtn:
                {
                    if (this._info) 
                    {
                        loc1 = parseInt(this._oneBetNumInputTx.text);
                        if (loc1 == 0) 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(44366));
                            return;
                        }
                        if (loc1 + this._info.betPlayerOne.myBetNumGold + this._info.betPlayerTwo.myBetNumGold > GameConst.ArenaCrossBetGoldMax) 
                        {
                            MsgManager.showRollTipsMsg(Language.getStringByParam(44387, GameConst.ArenaCrossBetGoldMax));
                            return;
                        }
                        if (this._oneBetNumInputTx.text === "") 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(44314));
                        }
                        else 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCrossGoToBetSomeOne, {"entityId": this._info.betPlayerOne.entityId, "num": parseInt(this._oneBetNumInputTx.text), "unit": _EPriceUnitGold}));
                        }
                    }
                    break;
                }
                case this._twoBetBtn:
                {
                    if (this._info) 
                    {
                        loc1 = parseInt(this._twoBetNumInputTx.text);
                        if (loc1 == 0) 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(44366));
                            return;
                        }
                        if (loc1 + this._info.betPlayerOne.myBetNumGold + this._info.betPlayerTwo.myBetNumGold > GameConst.ArenaCrossBetGoldMax) 
                        {
                            MsgManager.showRollTipsMsg(Language.getStringByParam(44387, GameConst.ArenaCrossBetGoldMax));
                            return;
                        }
                        if (this._twoBetNumInputTx.text === "") 
                        {
                            MsgManager.showRollTipsMsg(Language.getString(44314));
                        }
                        else 
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaCrossGoToBetSomeOne, {"entityId": this._info.betPlayerTwo.entityId, "num": parseInt(this._twoBetNumInputTx.text), "unit": _EPriceUnitGold}));
                        }
                    }
                    break;
                }
            }
            return;
        }

        /* internal  */confirmCoin(arg1: GTextInput): void
        {
            if (arg1.text == "") 
            {
                return;
            }
            var loc1=parseInt(arg1.text);
            if (loc1 > parseInt(this._myGoldTxt.text)) 
            {
                arg1.text = this._myGoldTxt.text;
                MsgManager.showRollTipsMsg(Language.getString(69229));
            }
            if (parseInt(arg1.text) == 0) 
            {
                arg1.text = "";
            }
            return;
        }

        public updateCoinNum(arg1: int): void
        {
            this._myGoldTxt.text = arg1.toString();
            if (this._oneBetNumInputTx.text !== "") 
            {
                this.confirmCoin(this._oneBetNumInputTx);
            }
            if (this._twoBetNumInputTx.text !== "") 
            {
                this.confirmCoin(this._twoBetNumInputTx);
            }
            this._myArenaCrossCoinTxt.text = Cache.instance.role.money.arenaCrossCoin.toString();
            return;
        }

        public updateInfo(arg1: SArenaCrossBetPlayerInfos): void
        {
            var sArenaCrossBetPlayerInfos: SArenaCrossBetPlayerInfos;

            var loc1;
            sArenaCrossBetPlayerInfos = arg1;
            this._info = sArenaCrossBetPlayerInfos;
            if (this._info.betPlayerOne.entityId.id != 0) 
            {
                this._oneBetBtn.enabled = true;
            }
            else 
            {
                this._oneBetBtn.enabled = false;
            }
            if (this._info.betPlayerTwo.entityId.id != 0) 
            {
                this._twoBetBtn.enabled = true;
            }
            else 
            {
                this._twoBetBtn.enabled = false;
            }
            this._oneName.text = this._info.betPlayerOne.name;
            this._twoName.text = this._info.betPlayerTwo.name;
            if (this._info.betPlayerOne.entityId.id != 0) 
            {
                AvatarInfo.getAvatar(this._info.betPlayerOne.camp, this._info.betPlayerOne.sex, AvatarType.BIG, (arg1: ImageInfo): void
                {
                    _oneHeadImage.bitmapData = arg1.bitmapData;
                    return;
                }, this._info.betPlayerOne.avatarId)
            }
            else 
            {
                this._oneHeadImage.bitmapData = null;
            }
            if (this._info.betPlayerTwo.entityId.id != 0) 
            {
                AvatarInfo.getAvatar(this._info.betPlayerTwo.camp, this._info.betPlayerTwo.sex, AvatarType.BIG, (arg1: ImageInfo): void
                {
                    _twoHeadImage.bitmapData = arg1.bitmapData;
                    return;
                }, this._info.betPlayerTwo.avatarId)
            }
            else 
            {
                this._twoHeadImage.bitmapData = null;
            }
            if (this._info.betPlayerOne.entityId.id != 0) 
            {
                this._oneServerTx.text = EntityUtil.getProxyName(this._info.betPlayerOne.entityId);
            }
            else 
            {
                this._oneServerTx.text = "";
            }
            if (this._info.betPlayerTwo.entityId.id != 0) 
            {
                this._twoServerTx.text = EntityUtil.getProxyName(this._info.betPlayerTwo.entityId);
            }
            else 
            {
                this._twoServerTx.text = "";
            }
            if (this._info.betPlayerOne.entityId.id != 0) 
            {
                this._oneInfoTx.text = "LV." + this._info.betPlayerOne.level + "   " + CareerConfig.instance.getInfoByCode(this._info.betPlayerOne.career).name;
            }
            else 
            {
                this._oneInfoTx.text = "";
            }
            if (this._info.betPlayerTwo.entityId.id != 0) 
            {
                this._twoInfoTx.text = "LV." + this._info.betPlayerTwo.level + "   " + CareerConfig.instance.getInfoByCode(this._info.betPlayerTwo.career).name;
            }
            else 
            {
                this._twoInfoTx.text = "";
            }
            this._oneWarfareTx.text = this._info.betPlayerOne.warfare.toString();
            this._twoWarfareTx.text = this._info.betPlayerTwo.warfare.toString();
            this._oneMyBetTx.text = this._info.betPlayerOne.myBetNumGold.toString();
            this._twoMyBetTx.text = this._info.betPlayerTwo.myBetNumGold.toString();
            this._oneBetNumInputTx.text = "";
            this._twoBetNumInputTx.text = "";
            return;
        }

        /* internal  */onLinkClickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            AIManager.onAutoPathAIControl(this._targetInfo);
            return;
        }

        /* internal  */onFlyFootClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            AIManager.onAIControl(this._targetInfo, AIType.AI_Convey);
            return;
        }

        /* internal */ /* var */_sp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_oneName: Object /* flash.text.TextField */;

        /* internal */ /* var */_twoName: Object /* flash.text.TextField */;

        /* internal */ /* var */_oneHeadImage: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_twoHeadImage: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_oneServerTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_twoServerTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_oneInfoTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_twoInfoTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_oneWarfareTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_twoWarfareTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_oneMyBetTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_twoMyBetTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_oneBetNumInputTx: GTextInput;

        /* internal */ /* var */_twoBetNumInputTx: GTextInput;

        /* internal */ /* var */_oneBetBtn: GButton;

        /* internal */ /* var */_twoBetBtn: GButton;

        /* internal */ /* var */filterArr: Array<any>;

        /* internal */ /* var */_myGoldTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_myArenaCrossCoinTxt: GTextFiled;

        /* internal */ /* var */_flyFoot: FlyFootBmp;

        /* internal */ /* var */_finalPosType: int;

        /* internal */ /* var */_finalPos: int;

        /* internal */ /* var */_info: SArenaCrossBetPlayerInfos;

        /* internal */ /* var */_targetInfo: TaskTargetInfo;

        /* internal */ /* var */glowFilterY: Object /* flash.filters.GlowFilter */;
    }
